package com.liqi.frame.comm.util;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;
import org.apache.shiro.subject.Subject;
import org.apache.shiro.web.mgt.DefaultWebSecurityManager;
import org.apache.shiro.web.session.mgt.DefaultWebSessionManager;

import java.util.Collection;

/**
 * Shiro工具类
 * @author liqi on 2017-05-27.
 */
public class ShiroUtil {
    public static Session getSession() {
        return getSubject().getSession();
    }

    public static Subject getSubject() {
        return SecurityUtils.getSubject();
    }

    public static Collection<Session> getActiveSessions(){
        DefaultWebSecurityManager securityManager =  (DefaultWebSecurityManager)SecurityUtils.getSecurityManager();
        DefaultWebSessionManager sessionManager = (DefaultWebSessionManager)securityManager.getSessionManager();
        return sessionManager.getSessionDAO().getActiveSessions();
    }
}
